package com.ymatou.iapi.livebuyer.testcase;

import java.util.ArrayList;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonArray;
import com.ymatou.iapi.livebuyer.parameter.QueryInProgressProductIdsBean;
import com.ymatou.iapi.livebuyer.service.QueryInProgressProductIdsCall;
import com.ymatou.iapi.productmanager.parameter.product.AddSellerProductRequest;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.LiveRoomCallService;
import com.ymttest.business.service.ProductManagerCallServiceV2;
import com.ymttest.database.model.LiveRoom;
import com.ymttest.utils.EnvSetup;
/**
*获取进行中直播的商品列表
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_QueryInProgressProductIds{
	private static QueryInProgressProductIdsBean queryinprogressproductidsBean;
	private static QueryInProgressProductIdsCall queryinprogressproductidsCall;
	private static int sellerId = Integer.parseInt(EnvSetup.getData("autotest_seller1"));
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取进行中直播的商品列表");
	}

	@Before
	public void caseUp() {
		queryinprogressproductidsBean=new QueryInProgressProductIdsBean();
		queryinprogressproductidsCall=new QueryInProgressProductIdsCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(queryinprogressproductidsCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_QueryInProgressProductIds_001() {
		Logger.start(true,"获取进行中直播的商品列表,成功");
		try {
			Logger.comment("创建商品");
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String pid = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(sellerId));
			LiveRoomCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), pid);
			LiveRoomCallService.SellerLiveOnline(createlive.getId(), createlive.getUserId());
			List<String> productIds=new ArrayList<>();
			productIds.add(pid);
			queryinprogressproductidsBean.setProductIds(productIds);
			queryinprogressproductidsCall.setData(queryinprogressproductidsBean);
			queryinprogressproductidsCall.callService();			
			Logger.verifyEquals("200", queryinprogressproductidsCall.getString("code"), "验证code");
			JsonArray ja = queryinprogressproductidsCall.getJsonObject().get("data").getAsJsonArray();
			Logger.verifyEquals(1, ja.size(), "验证数量");
			Logger.verifyEquals(pid, ja.get(0).getAsString(), "验证pid");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_QueryInProgressProductIds_002() {
		Logger.start(true,"不输入productIds失败");
		try {
			queryinprogressproductidsCall.setData(queryinprogressproductidsBean);
			queryinprogressproductidsCall.callService();			
			Logger.verifyEquals("100", queryinprogressproductidsCall.getString("code"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_QueryInProgressProductIds_003() {
		Logger.start(true,"混合输入在与不在直播中的商品正确输出直播商品");
		try {
			Logger.comment("创建商品");
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String pid = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			AddSellerProductRequest addpro2 = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String pid2 = ProductManagerCallServiceV2.addNewProduct(addpro2).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("创建商品：" + pid);
			Logger.comment("创建商品：" + pid2);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(sellerId));
			LiveRoomCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), pid);
			LiveRoomCallService.SellerLiveOnline(createlive.getId(), createlive.getUserId());
			List<String> productIds=new ArrayList<>();
			productIds.add(pid);
			productIds.add(pid2);
			queryinprogressproductidsBean.setProductIds(productIds);
			queryinprogressproductidsCall.setData(queryinprogressproductidsBean);
			queryinprogressproductidsCall.callService();			
			Logger.verifyEquals("200", queryinprogressproductidsCall.getString("code"), "验证code");
			JsonArray ja = queryinprogressproductidsCall.getJsonObject().get("data").getAsJsonArray();
			Logger.verifyEquals(1, ja.size(), "验证数量");
			Logger.verifyEquals(pid, ja.get(0).getAsString(), "验证pid");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_QueryInProgressProductIds_004() {
		Logger.start(true,"未开始时的直播商品不会返回");
		try {
			Logger.comment("创建商品");
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String pid = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(sellerId));
			LiveRoomCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), pid);
//			LiveRoomCallService.SellerLiveOnline(createlive.getId(), createlive.getUserId());
			List<String> productIds=new ArrayList<>();
			productIds.add(pid);
			queryinprogressproductidsBean.setProductIds(productIds);
			queryinprogressproductidsCall.setData(queryinprogressproductidsBean);
			queryinprogressproductidsCall.callService();			
			Logger.verifyEquals("200", queryinprogressproductidsCall.getString("code"), "验证code");
			JsonArray ja = queryinprogressproductidsCall.getJsonObject().get("data").getAsJsonArray();
			Logger.verifyEquals(0, ja.size(), "验证数量");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_QueryInProgressProductIds_005() {
		Logger.start(true,"暂停销售的直播商品不会返回");
		try {
			Logger.comment("创建商品");
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String pid = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(sellerId));
			LiveRoomCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), pid);
			LiveRoomCallService.SellerLiveOnline(createlive.getId(), createlive.getUserId());
			LiveRoomCallService.SuspendLiveProduct(createlive.getId(), pid);
			List<String> productIds=new ArrayList<>();
			productIds.add(pid);
			queryinprogressproductidsBean.setProductIds(productIds);
			queryinprogressproductidsCall.setData(queryinprogressproductidsBean);
			queryinprogressproductidsCall.callService();			
			Logger.verifyEquals("200", queryinprogressproductidsCall.getString("code"), "验证code");
			JsonArray ja = queryinprogressproductidsCall.getJsonObject().get("data").getAsJsonArray();
			Logger.verifyEquals(0, ja.size(), "验证数量");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_QueryInProgressProductIds_006() {
		Logger.start(true,"移除的直播商品不会返回");
		try {
			Logger.comment("创建商品");
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String pid = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(sellerId));
			LiveRoomCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), pid);
			LiveRoomCallService.SellerLiveOnline(createlive.getId(), createlive.getUserId());
			LiveRoomCallService.RemoveLiveProduct(createlive.getId(), pid);
			List<String> productIds=new ArrayList<>();
			productIds.add(pid);
			queryinprogressproductidsBean.setProductIds(productIds);
			queryinprogressproductidsCall.setData(queryinprogressproductidsBean);
			queryinprogressproductidsCall.callService();			
			Logger.verifyEquals("200", queryinprogressproductidsCall.getString("code"), "验证code");
			JsonArray ja = queryinprogressproductidsCall.getJsonObject().get("data").getAsJsonArray();
			Logger.verifyEquals(0, ja.size(), "验证数量");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}